//관련파일 - for.html
//내용 -구구단 출력
//작성자 이몸이시다
//작성일자 13.9.27

window.onload=function()
{
	var b = document.getElementById('btn');
	var r = document.getElementById('result');

	b.onclick = function()
	{
		
		var dan=document.getElementById('gugu').value;
		var i=0;
		var str='';
		
		for(i=1;i<10;i++)
		{
			str += dan + " * " + i + " = " + (dan*i)+'<br>';
		}
		r.innerHTML = str;
	};
	
	var b2 = document.getElementById('hap');
	var r2 = document.getElementById('hapResult');
	b2.onclick = function()
	{
		var x = parseInt(document.getElementById('x').value);
		var y = parseInt(document.getElementById('y').value);
		var i=0;
		var r=0;
		for(i=x;i<=y;i++)
		{
			r=r+i;
		}
		r2.innerHTML = r;
	};
	
	var gu_b = document.getElementById('gu');
	var gu_r = document.getElementById('guResult');
	gu_b.onclick = function()
	{
		var gu_1 = parseInt(document.getElementById('dan1').value);
		var gu_2 = parseInt(document.getElementById('dan2').value);
		var gu='<b>';
		var s=gu_1;
		var e=gu_2;
		var i=0;
		if(s>e)
		{
			s=gu_2;
			e=gu_1;
		}
		for(s;s<=e;s++)
		{
			if(s%2==1)
			{
				gu += "<font color=red>"; 
			}
			else if(s%2==0)
			{
				gu += "<font color=purple>"; 
			}
			if(s==0)
				continue;

			for(i=1;i<=9;i++)
			{
				gu += s + " * " + i + " = " + (s*i)+'<br>';
			}
			gu+="</font><br>";
		}
		gu+='</b>';
		gu_r.innerHTML = gu;
	};
};
